import 'package:flutter/material.dart';
import 'package:jicaimao_flutter/entity/account_bean.dart';
import 'package:jicaimao_flutter/utils/toast.dart';
import 'package:jicaimao_flutter/views/mine/my_chest_in_datils.dart';

class Purchase_Recordt extends StatefulWidget {
  final String label;

  @override
  _Purchase_RecordtState createState() => _Purchase_RecordtState();

  Purchase_Recordt({Key key, this.label}) : super(key: key);
}

class _Purchase_RecordtState extends State<Purchase_Recordt>
    with AutomaticKeepAliveClientMixin {
  List<AccountBeanResult> mData = List();

  @override
  bool get wantKeepAlive => true;
  String mScreen;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    mScreen = widget.label;
  }

  @override
  Widget build(BuildContext context) {
    super.build(context); // See AutomaticKeepAliveClientMixin.
//    return _Transfer_Details(context);
    return CustomScrollView(physics: ScrollPhysics(), slivers: <Widget>[
      SliverToBoxAdapter(
        child: _Transfer_Details(context),
      ),
      SliverList(
        delegate: SliverChildBuilderDelegate(
          (BuildContext context, int index) {
            return _DetailedItemData(context, mData);
          },
          childCount: 13,
        ),
      )
    ]);
  }

  ///转取明细
  Widget _Transfer_Details(BuildContext context) {
    return Container(
      color: Color(0xFFF6F5F5),
      child: Column(
        children: <Widget>[
          GestureDetector(
            child: Container(
              height: 45.0,
              padding: EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
              margin: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 5.0),
              color: Colors.white,
              child: Row(
                children: <Widget>[
                  new Image.asset(
                    'images/img_screen.png',
                    width: 30.0,
                    height: 30.0,
                  ),
                  Expanded(
                    child: new Text(mScreen == null ? "筛选" : mScreen.toString(),
                        style: new TextStyle(
                            fontWeight: FontWeight.normal,
                            fontSize: 15.0,
                            color: Color(0xFF333333))),
                    flex: 1,
                  ),
                  new Image.asset(
                    "images/img_upper.png",
                    width: 12.0,
                    height: 12.0,
                  ),
                ],
              ),
            ),
            onTap: () {
              showSelecDialog(
                context,
              );
            },
          ),
        ],
      ),
    );
  }

  ///
  void showSelecDialog(
    BuildContext context,
  ) {
    showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new Scaffold(
            backgroundColor: Color(0xFFF6F5F5),
            appBar: AppBar(
              centerTitle: true,
              backgroundColor: Colors.white,
              leading: IconButton(
                icon: Icon(
                  Icons.arrow_back_ios,
                  color: Colors.grey,
                ),
                onPressed: () => Navigator.pop(context),
              ),
              title: Text(
                '账目',
                style: TextStyle(
                  fontSize: 14,
                  color: Colors.black,
                ),
              ),
            ),
//            body: Container(
            body: Column(
              children: <Widget>[
                Container(
                    height: 50,
                    color: Colors.white,
                    alignment: Alignment.center,
                    child: Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            Expanded(
                              child: Container(
                                margin:
                                    EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
                                alignment: Alignment.center,
                                child: Text(
                                  '申购记录',
                                  style: TextStyle(
                                      fontSize: 14,  color: Colors.black87,),
                                ),
                              ),
                              flex: 1,
                            ),
                            Expanded(
                              child: Container(
                                margin:
                                    EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
                                alignment: Alignment.center,
                                child: Text(
                                  '转取明细',
                                  style: TextStyle(
                                    fontSize: 14,

                                      color: Colors.purpleAccent
                                  ),
                                ),
                              ),
                              flex: 1,
                            ),
                          ],
                        ),
                        Row(
                          children: <Widget>[
                            Expanded(
                              child: Container(
                                margin:
                                    EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
                                alignment: Alignment.center,
                                child: new Divider(
                                  height: 2,
                                  color: Colors.white,
                                ),
                              ),
                              flex: 1,
                            ),
                            Expanded(
                              child: Container(
                                margin:
                                    EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
                                alignment: Alignment.center,
                                child: new Divider(
                                  height: 2,

                                  color: Colors.purpleAccent,
                                ),
                              ),
                              flex: 1,
                            ),
                          ],
                        ),
                      ],
                    )),
                Container(
                  height: 45.0,
                  padding: EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
                  margin: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
                  color: Colors.white,
                  child: Row(
                    children: <Widget>[
                      new Image.asset(
                        'images/img_screen.png',
                        width: 30.0,
                        height: 30.0,
                      ),
                      Expanded(
                        child: new Text(
                            mScreen == null ? "筛选" : mScreen.toString(),
//                            mScreen.toString(),
                            style: new TextStyle(
                                fontWeight: FontWeight.normal,
                                fontSize: 15.0,
                                color: Color(0xFF333333))),
                        flex: 1,
                      ),
                      new Image.asset(
                        "images/img_upper.png",
                        width: 12.0,
                        height: 12.0,
                      ),
                    ],
                  ),
                ),
                CommonItemSelect(
                  onTabItem: () {
                    Navigator.pop(context);
                    mScreen = "全部";
                    setState(() {
                      mScreen = "全部";
                    });
                  },
                  title: '全部',
                  color: Colors.grey,
                  itemHeight: 40.0,
                ),
                CommonItemSelect(
                  onTabItem: () {
                    Navigator.pop(context);
                    mScreen = "转入";
                    setState(() {
                      mScreen = "转入";
                    });
                  },
                  color: Colors.grey,
                  title: '转入',
                  itemHeight: 40.0,
                ),
                CommonItemSelect(
                  title: '转出',
                  itemHeight: 40.0,
                  color: Colors.grey,
                  onTabItem: () {
                    Navigator.pop(context);
                    mScreen = "转出";
                    setState(() {
                      mScreen = "转出";
                    });
                  },
                ),
              ],
            ),
          );
        });
  }

  ///转取明细
  Widget _DetailedItemData(BuildContext context, List<AccountBeanResult> list) {
//    if (mData == null || mData.isEmpty) {
//      return Container(
//          margin: EdgeInsets.fromLTRB(150.0, 180.0, 150.0, 0.0),
//          child: new Column(
//            children: <Widget>[
//              Image.asset(
//                'images/no_data.png',
//                width: 80.0,
//                height: 80.0,
//              ),
//              Text('暂无数据')
//            ],
//          ));
//    } else {
//      return listViewListTile(list);
//    }

    return _DetailedListViewListTile(list);
  }

  ///转取明细
  Widget _DetailedListViewListTile(List<AccountBeanResult> list) {
    return ListView.builder(
      scrollDirection: Axis.vertical,
      //是否倒序显示 默认正序 false  倒序true
      reverse: false,
      primary: true,
      //确定每一个item的高度 会让item加载更加高效
//        itemExtent: 50.0,
      shrinkWrap: true,
      //item 数量
//      itemCount: list.length,
      itemCount: 1,
      //滑动类型设置
//      physics: new ClampingScrollPhysics(),
//      physics: AlwaysScrollableScrollPhysics(),
      physics: NeverScrollableScrollPhysics(),
      //滑动监听
//        controller ,
      itemBuilder: (context, i) => new InkWell(
            child: new Column(
              children: <Widget>[
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        height: 45,
                        alignment: Alignment.centerLeft,
                        color: Colors.white,
                        padding: EdgeInsets.fromLTRB(15.0, 0.0, 0.0, 0.0),
                        child: Text(
                          '转出',
                          style: new TextStyle(
                              fontWeight: FontWeight.w600,
                              fontSize: 16.0,
                              color: Color(0xFF333333)),
                        ),
                      ),
                      flex: 1,
                    ),
                    Expanded(
//                      height: 45,
                      child: Container(
                        height: 45,
                        alignment: Alignment.centerRight,
                        color: Colors.white,
                        padding: EdgeInsets.fromLTRB(0.0, 0.0, 15.0, 0.0),
                        child: new Text(
                          '-200000.0000 BSC',
                          style: new TextStyle(
                              fontSize: 16.0, color: Color(0xFF333333)),
                        ),
                      ),
                      flex: 1,
                    ),
                  ],
                ),
                Row(
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        height: 45,
                        padding: EdgeInsets.fromLTRB(10.0, 0.0, 0.0, 0.0),
                        alignment: Alignment.centerLeft,
                        color: Colors.white,
                        child: Text(
                          '2019-01-28 15:23:00',
                          style: new TextStyle(
                              fontSize: 16.0, color: Color(0xFF999999)),
                        ),
                      ),
                      flex: 1,
                    ),
                    Expanded(
                      child: Container(
                        height: 45,
                        padding: EdgeInsets.fromLTRB(0.0, 0.0, 15.0, 0.0),
                        alignment: Alignment.centerRight,
                        color: Colors.white,
                        child: new Text(
                          'B生活',
                          style: new TextStyle(
                              fontSize: 16.0, color: Color(0xFF333333)),
                        ),
                      ),
                      flex: 1,
                    ),
                  ],
                ),
                new Divider(
                  height: 2,
                ),
              ],
            ),
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
//                    builder: (context) => MyChestInDatils(list[i].list)),
                    builder: (context) => MyChestInDatils()),
              );
            },
          ),
    );
  }
}

class CommonItemSelect extends StatelessWidget {
  CommonItemSelect({this.onTabItem, this.title, this.color, this.itemHeight});

  final String title;
  final Color color;
  final double itemHeight;
  final VoidCallback onTabItem;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTabItem,
      child: Container(
        padding: EdgeInsets.only(left: 20.0, top: 1.0),
        color: Colors.white,
        alignment: Alignment.centerLeft,
        height: itemHeight,
        child: Text(
          title,
          style: TextStyle(
              color: color == null ? Colors.blue : color, fontSize: 16.0),
        ),
      ),
    );
  }
}
